package cn.zhengzhou.springbootmybatis.demo;

import java.util.concurrent.*;

public class ThreadPoolTest {
    public static void main(String[] args) {
        //  参数  核心线程数量  最大线程数  临时线程存活时间  任务队列每次存活数量 创建线程  线程拒绝策略
        ExecutorService pool = Executors.newCachedThreadPool();

        Future<String> f1 = pool.submit(new RunnableNew(100));
        Future<String> f2 = pool.submit(new RunnableNew(200));
        Future<String> f3 = pool.submit(new RunnableNew(300));
        Future<String> f4 = pool.submit(new RunnableNew(400));

        try {
            System.out.println(f1.get());
            System.out.println(f2.get());
            System.out.println(f3.get());
            System.out.println(f4.get());
        } catch (Exception e) {
            e.printStackTrace();
        }
        //3.关闭线程池  一般不用
        //pool.shutdown();
        //立即结束线程
//        pool.shutdownNow();
    }
}
